<!DOCTYPE html>
            
<HTML>
<HEAD>
<meta name="booktitle" content="Developing Applications With Objective Caml" >
 <meta charset="ISO-8859-1"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<META name="GENERATOR" content="hevea 1.05-7 of 2000-02-24">
<META NAME="Author" CONTENT="Christian.Queinnec@lip6.fr">
<LINK rel=stylesheet type="text/css" href="videoc-ocda.css">
<script language="JavaScript" src="videoc.js"><!--
//--></script>
<TITLE>
 Standalone Executables
</TITLE>
</HEAD>
<BODY class="regularBody">
<A HREF="book-ora066.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora068.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2> Standalone Executables</H2>
<A NAME="sec-standalone"></A>
<A NAME="@concepts142"></A>
<A NAME="@fonctions199"></A>
<A NAME="@concepts143"></A>A standalone executable is a program that does not depend an Objective CAML installation to run. This facilitates the distribution of binary applications and robustness against runtime library changes across
Objective CAML versions.<BR>
<BR>
The Objective CAML native compiler produces standalone executables by default. But
without the <TT>-custom</TT> option, the bytecode compiler produces an
executable which requires the bytecode interpreter <EM>ocamlrun</EM>. Imagine the file <TT>example.ml</TT> is as follows:
<PRE>
let f x = x + 1;;
print_int (f 18);;
print_newline();;
</PRE>Then the following command produces the (approximately 8k) file <TT>example.exe</TT>:
<PRE>
ocamlc -o example.exe example.ml
</PRE>This file can be executed by the Objective CAML bytecode interpreter:
<PRE>
$ ocamlrun example.exe
19
</PRE>The interpreter executes the Zinc machine instructions contained in the file <TT>example.exe</TT>.<BR>
<BR>
Under Unix, the first line of the file <TT>example.exe</TT> contains the location of the interpreter, for example:
<PRE>
#!/usr/local/bin/ocamlrun
</PRE>This means the file can be executed directly (without using <TT>ocamlrun</TT>. Like
a shell-script, executing the file in turn runs the program specified on the first
line, which is then used to interpret the remainder of the file. If <TT>ocamlrun</TT> can't be found, execution will fail and the error message <TT>Command not found</TT> will be displayed.<BR>
<BR>
The same compilation with the option <TT>-custom</TT> produces a standalone executable with name <TT>exauto.exe</TT>:
<PRE>
ocamlc -custom -o exauto.exe example.ml
</PRE>This time the file is about 85K, as it contains the Zinc interpreter as well as the program bytecode. 
This file can be executed directly or copied to another machine (using the same
CPU/Operating System) for execution.<BR>
<BR>
<HR>
<A HREF="book-ora066.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora068.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
